package com.zhr.business.sys.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhr.business.sys.domain.SysGoods;
import com.zhr.business.sys.param.CreateUserParam;
import com.zhr.business.sys.service.SysGoodsService;
import com.zhr.business.sys.vo.SysGoodsVO;
import com.zhr.common.annotation.SysLogInterface;
import com.zhr.common.api.Result;
import com.zhr.common.enums.BusinessType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController
@RequiredArgsConstructor
@Tag(name = "SysGoodsController", description = "商品信息控制层")
@RequestMapping("/goods")
public class SysGoodsController {
    private final SysGoodsService sysGoodsService;

    @Operation(summary = "list 分页列表")
    @Parameters({
            @Parameter(name = "current", description = "当前页", required = true, example = "1"),
            @Parameter(name = "size", description = "每页显示条数", required = true, example = "10"),
            @Parameter(name = "goodname", description = "商品名称"),
    })

    @GetMapping(value = "/getGoodList")
    @SysLogInterface(title = "查询商品信息", businessType = BusinessType.OTHER)
    public Result<IPage<SysGoodsVO>> getGoodList(@Parameter(hidden = true) @RequestParam Map<String, Object> params) {
        System.out.println(params);
        IPage<SysGoodsVO> sysGoods = sysGoodsService.getList(params);
        return Result.success(sysGoods);
    }
    @PostMapping(value = "/updateGood")
    public Result<String> updateGood(@RequestBody SysGoods SysGoods) {
        System.out.println("更新商品信息为"+SysGoods);
        return Result.success(String.valueOf(sysGoodsService.updateById(SysGoods)));
    }
    @PostMapping(value = "/createGood")
    public Result<String> addGood(@RequestBody SysGoods SysGoods) {
        System.out.println("商品信息为"+SysGoods);
        return Result.success(String.valueOf(sysGoodsService.save(SysGoods)));
    }
    @PostMapping(value = "/deleteGood")
    public Result<String> deleteGood(@RequestBody SysGoodsVO SysGoodsVO) {
        System.out.println("删除商品ID为"+SysGoodsVO.getId());
        return Result.success(String.valueOf(sysGoodsService.removeById(SysGoodsVO.getId())));
    }
}
